<template>
  <span v-if="show">
    <slot name="auth"></slot>
  </span>
</template>
<script>
let _this = {};
export default {
  data() {
    return {
      show: false,
      url: {
        checkAuth: "/permission/auth/check",
        permission: "/permission/getPermissions",
      },
    };
  },
  props: {
    code: {
      // 必须提供字段
      required: false,
      type: String,
    },
  },

  mounted() {},
  created() {
    console.log(this.code);
    if (this.code == "none" || this.code == "") {
      return;
    }
    if (this.code == null || this.code == "") {
      this.show = false;
      return;
    }
    // 从本地缓存拿
    let userNullArr = [null, undefined, "null", "undefined"];
    let user = this.$getUser();
    debugger
    let arr = user.permission;
    if (arr.indexOf("*:*:*") > -1) {
      this.show = true;
      return;
    } else {
      this.$get(this.url.checkAuth, { code: this.code }).then((res) => {
        if (res.R) {
          this.show = res.data;
        }
      });
    }
  },
};
</script>
